retext-visit
retext node visitor.
Installation
npm:
$ npm install retext-visit
Component.js:
$ component install wooorm/retext-visit
Bower:
$ bower install retext-visit
Duo:
var visit = require('wooorm/retext-visit');
Usage
var Retext = require('retext');
var visit = require('retext-visit');
var inspect = require('retext-inspect');
var retext = new Retext()
.use(inspect)
.use(visit);
API
retext.parse('A simple English sentence.', function (err, tree) {
if (err) throw err;
tree.head.head.visit(function (node) {
console.log(node);
});
});
Invoke callback
for every descendant of the operated on context.
Parameters:
callback
(function(Node): boolean?
): Visitor. Stops visiting when it returns false
.
retext.parse('A simple English sentence.', function (err, tree) {
if (err) throw err;
tree.visit(tree.WORD_NODE, function (node) {
console.log(node);
});
});
Invoke callback
for every descendant of the context of type
.
Parameters:
type
: Type of visited nodes.callback
(function(Node): boolean?
): Visitor. Stops visiting when the return value is false
.
Performance
On a MacBook Air.
Visit every node
7,806 op/s » A section
670 op/s » An article
Visit every word node
6,249 op/s » A section
521 op/s » An article
License
MIT © Titus Wormer